<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

    public function __construct(){
        parent::__construct();
		$this->common_model->checkpurview();
		$this->jxcsys = $this->session->userdata('jxcsys');
    }
	
	public function index(){
	    //add by michen 20170820 for 修改登录异常 begin
	    if(!strstr($_SERVER['REQUEST_URI'], 'home/index'))
	        redirect('home/index', 'refresh');
	    //add by michen 20170820 for 修改登录异常 end
	    $data['uid']      = $this->jxcsys['uid'];
		$data['name']     = $this->jxcsys['name'];
		$data['roleid']   = 0;
		$data['username'] = $this->jxcsys['username']; 
        $data['system']   = $this->common_model->get_option('system'); 
		$data['rights']   = $this->common_model->get_admin_rights(); 
		$data['orgName'] = $this->jxcsys['roleid'] == 0 ? '系统管理员' :$this->jxcsys['orgName'];//add for more
		$this->load->view('index',$data);
	}
	
	public function main(){
		$this->load->view('main');
	}
	

    public function set_password(){
		$userido=intval($this->input->get('userid',TRUE));
		$userid = $userido>0?$userido:$this->jxcsys['uid'];
		$data = str_enhtml($this->input->post(NULL,TRUE));
		if (is_array($data)&&count($data)>0) {
			$userid = intval($data['buyerId']);
			if(!empty($data['newPassword']))$info['userpwd'] = md5($data['newPassword']);
			if(!empty($data['validall'])){
				$info['validall'] = $data['validall']=='1'? 1 :0;
			}
			$info['mobile']  = $data['buyerMobile'];
			$info['name']    = $data['buyerName'];
			$info['validdate']    = $data['validdate'];
			$this->mysql_model->get_count('admin','(uid<>'.$userid.') and mobile='.$info['mobile'].'') >0 && str_alert(-1,'该手机号已被使用,请更换手机号码'); 
		    $sql = $this->mysql_model->update('admin',$info,'(uid='.$userid.')');
			if ($sql) {
				$this->common_model->logs('密码修改成功 UID：'.$userid.' 真实姓名改为：'.$info['name']);
				str_alert(200,'密码修改成功');
			}
			str_alert(-1,'设置独立密码失败，请稍候重试！');
		} else {
		    $data = $this->mysql_model->get_rows('admin','(uid='.$userid.')');  
			$data['editinfo'] = $userido > 0 ? 'editinfo' : 'main';			
		    $this->load->view('set_password',$data);
		}
	}
	
	public function set_password2(){
	    if($this->jxcsys['roleid'] != 0)
	        str_alert(-1,'重置密码功能只有管理员才可以使用,请确认！');
	    $data = str_enhtml($this->input->post(NULL,TRUE));
	    $userId = $data['userId'];
	    if (is_array($data)&&count($data)>0) {
	        $info['userpwd'] = md5($data['password']);
	        $sql = $this->mysql_model->update('admin',$info,'(uid='.$userId.')');
	        if ($sql) {
	            $this->common_model->logs('强制密码修改成功 UID：'.$userId);
	            str_alert(200,'密码修改成功');
	        }
	        str_alert(-1,'设置独立密码失败，请稍候重试！');
	    } else {
	        str_alert(-1,'设置独立密码失败，参数为空！');
	    }
	}
	

	public function Services(){
		die('jQuery110202928952066617039_1430920204305({"status":200,"msg":"success","data":[{"msgid":"20000000122"
,"msglinkcolor":"d9254a","msglink":"","msgtitle":"售后热线服务时间临时调整通知（5.6-5.8）>>"},{"msgid":"20000000119"
,"msglinkcolor":"d9254a","msglink":"index.html","msgtitle"
:"推荐送ipad mini，购买就返利>>"},{"msgid":"20000000115","msglinkcolor":"d9254a","msglink":"","msgtitle":">>"},{"msgid":"20000000068","msglinkcolor":"d9254a","msglink":"","msgtitle":">
>"}]})');
		 
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */